package com.example.springboottestservice.postprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
 * @author wuxinxin
 */
@Component
public class MyDestructionAwareBeanPostProcessor implements DestructionAwareBeanPostProcessor {

    public MyDestructionAwareBeanPostProcessor() {
        System.out.println("MyDestructionAwareBeanPostProcessor");
    }

    @Override
    public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException{
        System.out.println("MyDestructionAwareBeanPostProcessor postProcessBeforeDestruction");
    }

    @Override
    public boolean requiresDestruction(Object bean) {
        System.out.println("MyDestructionAwareBeanPostProcessor requiresDestruction");
        return true;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("MyDestructionAwareBeanPostProcessor postProcessBeforeInitialization");
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("MyDestructionAwareBeanPostProcessor postProcessAfterInitialization");
        return bean;
    }
}
